//
//  CreateJobFirstViewController.swift
//  GreenDeal
//
//  Created by Moennig Q on 1/3/2023.
//  选择company & Agent

import UIKit
import Rswift
class CreateJobCompanyAgentVC: BaseViewController {
    let customView = CreateJobCompanyAgentView(topBGImageName: "createjob_companny_agent_top_bg")
    var editFlag: Bool = false
    override func viewDidLoad() {
        super.viewDidLoad()
        self.initUI()
        self.loadData()
    }
    //
    private func initUI(){
        self.view = self.customView
        self.customView.setTitleInfo(R.string.localizable.summary())
        self.customView.setData()
    }
    
    private func loadData(){
        let service = CreateJobService()
        service.setBlockAfterNetwork { [weak self] (result, _) in
            guard let strongSelf = self else {return}
            ModelViewUtil.shared.hideLoadingView()
            if let list = result as? [CompanyModel]{
                if list.count == 1 && strongSelf.customView.viewModel.summaryViewModel.company_id == 0{//只有一条数据，默认选中
                    strongSelf.customView.viewModel.summaryViewModel.company_id = list[0].id
                    strongSelf.customView.viewModel.summaryViewModel.company_name = list[0].name
                }
                strongSelf.customView.companyListObserver.accept(list)
                strongSelf.customView.getAgentList()
            }
        } errorBlock: { code, error in
            ModelViewUtil.shared.hideLoadingView()
            Tool().showErrorInfo(code, error)
        }
        ModelViewUtil.shared.showLoadingView(R.string.localizable.loading())
        service.getCompanyList()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(true, animated: false)
    }
}
